import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import { CustomValidator } from 'choerodon-ui/pro/lib/validator/Validator';


const rangeValidator: CustomValidator = async (value: Date | undefined, name: string | undefined) => {
  console.log(`[validation ${name} value]`, value);
  return true;
};

function handleDataSetChange({ value, oldValue }: { value: Date, oldValue: Date }) {
  console.log('[range dataset newValue]', value, '[oldValue]', oldValue);
}

const rangeTime = (): [string, string] => {
  return (['start', 'end']);
};

const DateDs = () => ({
  autoCreate: true,
  fields: [
    {
      name: 'date',
      type: FieldType.date,
      range: rangeTime(),
      defaultValue: { start: '1984-11-22', end: new Date() },
      required: true,
      validator: rangeValidator,
    },
    {
      name: 'date2',
      type: FieldType.date,
      range: true,
      defaultValue: ['1985-11-22', new Date()],
      validator: rangeValidator,
    },
    {
      name: 'multipleDate',
      type: FieldType.date,
      range: true,
      multiple: true,
      required: true,
    },
    {
      name: 'time',
      type: FieldType.time,
      range: true,
    },
  ],
  events: {
    update: handleDataSetChange,
  },
});

export default DateDs;